<template>
  <div class="login-container">
    <div class="logo" />
    <div class="form">
      <el-card shadow="never" class="login-card">
        <h1 class="el-icon-trophy">
          人 力 资 源 后 台 管 理
        </h1>
        <!--登录表单-->
        <el-form ref="from" :model="from" :rules="fromRules">
          <el-form-item prop="mobile">
            <el-input
              v-model="from.mobile"
              prefix-icon="el-icon-user-solid"
              placeholder="请输入手机号"
            />
          </el-form-item>

          <el-form-item prop="password">
            <el-input
              v-model="from.password"
              prefix-icon="el-icon-unlock"
              placeholder="请输入密码"
              show-password
            />
          </el-form-item>

          <el-form-item prop="security">
            <!-- <el-input prefix-icon="el-icon-sunny" placeholder="验证码" /> -->
            <el-input
              v-model="from.security"
              prefix-icon="el-icon-sunny"
              placeholder="9528"
              style="height:30px"
            >
              <template slot="append">
                <b style="color:red"> 9 5 2 8</b>
              </template>
            </el-input>
          </el-form-item>

          <el-form-item prop="isAll">
            <el-checkbox v-model="from.isAll">用户平台使用协议</el-checkbox>
          </el-form-item>

          <el-form-item>
            <el-button style="width:350px" type="primary" @click="subLonin">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      from: {
        // 开发环境设置默认的账号信息,生产环境有用户输入
        mobile: process.env.NODE_ENV === 'development' ? '13800000002' : '',
        password: process.env.NODE_ENV === 'development' ? '123456' : '',
        isAll: process.env.NODE_ENV === 'development',
        security: 9528
      },
      fromRules: {
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { pattern: /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/, message: '手机号格式不正确', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ],
        security: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ],
        isAll: [
          { validator: (rule, value, callback) => {
            value ? callback() : callback(new Error('请勾选用户平台协议'))
          } }
        ]
      }
    }
  },
  methods: {
    subLonin() {
      this.$refs.from.validate(async(valid) => {
        if (!valid) { return }
        await this.$store.dispatch('user/login', this.from)
        this.$router.push('/')
      })
    }
  }
}
</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;
  background: rgba(38, 72, 176) url(../../assets/common/login_back.png)
    no-repeat center / cover;
  .logo {
    flex: 4;
    border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;

  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-right: 200px;

    .el-card {
      border: none;
      padding: 0;
    }
    h1 {
      color: rgb(94, 144, 244);
      padding-left: 20px;
      font-size: 28px;
    }
    .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }
    .el-checkbox {
      color: #606266;
    }
  }
}
</style>
